#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
#include <assert.h>
int my_printf(const char* format, ...)
{




    return 0;
}
char ks[1024] = {0};


int is_enabled()
{
    int ret = 0;
    if(ks[0] == 0 && ks[1] == 0 && ks[2] == 0) {
        if(*(int*)(ks) == 0) {
            ret = 1;
        }
    }
    return ret;
}



#define TIMES   (1000*1000)



int time_no_call()
{
    struct timeval tvs, tve;
    gettimeofday(&tvs, NULL);

    int i;
    for(i=0; i<TIMES; i++) {
    }

    assert(i == TIMES);
    gettimeofday(&tve, NULL);
    long usec = (tve.tv_sec-tvs.tv_sec)*1e6 + (tve.tv_usec-tvs.tv_usec);
    printf("%36s : %lu\n", __FUNCTION__, usec);

    return 0;
}


int time_if1()
{
    struct timeval tvs, tve;
    gettimeofday(&tvs, NULL);

    int i;
    for(i=0; i<TIMES; i++) {
        if(ks[0] == 0) {

        }
    }

    assert(i == TIMES);
    gettimeofday(&tve, NULL);
    long usec = (tve.tv_sec-tvs.tv_sec)*1e6 + (tve.tv_usec-tvs.tv_usec);
    printf("%36s : %lu\n", __FUNCTION__, usec);

    return 0;
}


int time_is_enabled()
{
    struct timeval tvs, tve;
    gettimeofday(&tvs, NULL);

    int i;
    for(i=0; i<TIMES; i++) {
        if(!is_enabled()) {
            break;
        }
    }

    assert(i == TIMES);
    gettimeofday(&tve, NULL);
    long usec = (tve.tv_sec-tvs.tv_sec)*1e6 + (tve.tv_usec-tvs.tv_usec);
    printf("%36s : %lu\n", __FUNCTION__, usec);

    return 0;
}


int time_fprintf_null()
{
    struct timeval tvs, tve;
    gettimeofday(&tvs, NULL);

    FILE* fp;
    fp = fopen("/dev/null", "w");

    int i;
    for(i=0; i<TIMES; i++) {
        fprintf(fp, "%s %s %dfjskdjfslfjsdk\n", "fskdfjslkfd", "fsjkdfhjjhfd", 100);
    }

    assert(i == TIMES);
    gettimeofday(&tve, NULL);
    long usec = (tve.tv_sec-tvs.tv_sec)*1e6 + (tve.tv_usec-tvs.tv_usec);
    printf("%36s : %lu\n", __FUNCTION__, usec);

    return 0;
}


int time_snprintf()
{
    struct timeval tvs, tve;
    gettimeofday(&tvs, NULL);

    int i;
    for(i=0; i<TIMES; i++) {
        char str[1024];
        snprintf(str, 1024, "%s %s %dfjskdjfslfjsdk\n", "fskdfjslkfd", "fsjkdfhjjhfd", 100);
    }

    assert(i == TIMES);
    gettimeofday(&tve, NULL);
    long usec = (tve.tv_sec-tvs.tv_sec)*1e6 + (tve.tv_usec-tvs.tv_usec);
    printf("%36s : %lu\n", __FUNCTION__, usec);

    return 0;
}


int time_snprintf1()
{
    struct timeval tvs, tve;
    gettimeofday(&tvs, NULL);

    int i;
    char str[1024];
    for(i=0; i<TIMES; i++) {
        snprintf(str, 1024, "%s %s %dfjskdjfslfjsdk\n", "fskdfjslkfd", "fsjkdfhjjhfd", 100);
    }

    assert(i == TIMES);
    gettimeofday(&tve, NULL);
    long usec = (tve.tv_sec-tvs.tv_sec)*1e6 + (tve.tv_usec-tvs.tv_usec);
    printf("%36s : %lu\n", __FUNCTION__, usec);

    return 0;
}


int main()
{
    time_no_call();
    time_if1();
    time_is_enabled();
    time_fprintf_null();
    time_snprintf();
    time_snprintf1();


    return 0;
}




